package com.yanqu.road.entity.autodata.hotpotjump;

import java.util.ArrayList;
import java.util.List;

public class HotpotJumpGrid {
    private int x;
    private int y;
    private int hp;
    private int hpMax;
    private int shield;
    private List<List<Integer>> effects = new ArrayList<>();
    public HotpotJumpGrid() {
    }

    public HotpotJumpGrid(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getHpMax() {
        return hpMax;
    }

    public void setHpMax(int hpMax) {
        this.hpMax = hpMax;
    }

    public int getShield() {
        return shield;
    }

    public void setShield(int shield) {
        this.shield = shield;
    }

    public List<List<Integer>> getEffects() {
        return effects;
    }

    public void setEffects(List<List<Integer>> effects) {
        this.effects = effects;
    }

    public static List<HotpotJumpGrid> cloneList(List<HotpotJumpGrid> effectGrids) {
        List<HotpotJumpGrid> list = new ArrayList<>();
        for (HotpotJumpGrid effectGrid : effectGrids) {
            list.add(effectGrid.clone());
        }
        return list;
    }

    public HotpotJumpGrid clone() {
        HotpotJumpGrid clone = new HotpotJumpGrid();
        clone.x = this.x;
        clone.y = this.y;
        clone.hp = this.hp;
        clone.hpMax = this.hpMax;
        clone.shield = this.shield;
        for (List<Integer> effect : this.effects) {
            clone.effects.add(new ArrayList<>(effect));
        }

        return clone;
    }

    public int calcPostKey() {
        return x * 1000 + y;
    }

    public List<Integer> findEffectBySkillId(int skillId) {
        for (List<Integer> effect : effects) {
            if (effect.get(0) == skillId) {
                return effect;
            }
        }
        return null;
    }

    /**
     * 重复效果只更新回合,不叠加回合
     * @param skillId
     * @param round
     */
    public void addEffect(int skillId, int round, int value) {
        List<Integer> effectBySkillId = findEffectBySkillId(skillId);
        if (effectBySkillId == null) {
            effects.add(new ArrayList<Integer>() {{
                add(skillId);
                add(round);
                add(value);
            }});
        }else {
            effectBySkillId.set(1, round);
            effectBySkillId.set(2, value);
        }
    }

    /**
     * 效果减一回合
     */
    public void effectDecOneRound() {
        for (List<Integer> effect : effects) {
            effect.set(1, effect.get(1) - 1);
        }

        List<List<Integer>> tempEffects = new ArrayList<>();
        for (List<Integer> effect : effects) {
            if (effect.get(1) > 0) {
                tempEffects.add(effect);
            }
        }
        effects = tempEffects;
    }
}
